#!/usr/bin/perl -w # for syntax highlighting

use gri_secmgr qw(get_cookie_value got_cookie);
use gri_database;
use Data::Dumper;
use MIME::Base64;

sub mm_form_docrepos_replace_document_upload_populate {
my $document_sha1=shift;
my $lname=shift;

	if(! got_cookie(name => "gri_dbm_intranet")) {
		print STDERR "mm_send_email: User not logged in - no email sent!\n";
		return "Unable to send mail - user not logged in.";
	}
	my $v=get_cookie_value(name=>"gri_dbm_intranet");
	if($v =~ /^public\s+/) {
		print STDERR "mm_form_docrepos_upload_file: User logged in as public - upload not possible!\n";
		return "Unable to upload file - user logged in as 'public'";
	}
	$v=~ s/\s+.*//;
	my $db_dir=$::GRI_FRONTEND->get_global_directory("database");
	my $DB=new gri_database("$db_dir/gri.db");
	$file_name="" if (!defined($file_name) || $file_name eq "?file_name - not defined?");
	# Grab the existing details from the file - which might be edited...
	my ($rc,$dets)=$DB->get_details_by_sha1(sha1 => $document_sha1);
	if($rc!=1) {
		return "Error: Unable to retrieve document details via sha1!";
	}
	$file_description=decode_base64($dets->{description});
	$file_actual="";
	$file_sections=$dets->{sections};

my $s="
    <tr class=gri_headerrow>
      <td class=gri_cell colspan=3>Replacement Document Repository Upload Details</td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell colspan=3>&nbsp;</td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell><font class=stdtextlarge>Name:</font></td>
      <td class=gri_cell>&nbsp;&nbsp;&nbsp;</td>
      <td class=gri_cell>
        <INPUT TYPE=\"text\" VALUE=\"$file_name\" NAME=\"name\" SIZE=\"60\" MAXLENGTH=\"40\">
      </td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell colspan=3>&nbsp;</td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell><font class=stdtextlarge>Description:</font></td>
      <td class=gri_cell>&nbsp;&nbsp;&nbsp;</td>
      <td class=gri_cell>
        <TEXTAREA NAME=\"description\" COLS=60 ROWS=5>$file_description</TEXTAREA>
      </td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell colspan=3>&nbsp;</td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell><font class=stdtextlarge>File to Upload:</font></td>
      <td class=gri_cell>&nbsp;&nbsp;&nbsp;</td>
      <td class=gri_cell>
        <INPUT TYPE=\"file\" NAME=\"actual\" SIZE=40>
      </td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell colspan=3>&nbsp;</td>
    </tr>\n";
    return $s;
}

1;

